package cn.itcast.hotel.controller;

import cn.itcast.hotel.pojo.PageResult;
import cn.itcast.hotel.pojo.RequestParams;
import cn.itcast.hotel.service.IHotelService;
import cn.itcast.hotel.service.impl.HotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/hotel")
public class HotelController {

    @Autowired
    private IHotelService hotelService;

    /*Request URL: http://localhost:8089/hotel/list
    Request Method: POST
    {"key":"","page":1,"size":5,"sortBy":"default","city":"上海"}*/
    @PostMapping("/list")
    public PageResult list(@RequestBody RequestParams requestParams){
        log.info("[list接收到数据为：RequestParams{}]",requestParams.toString());
        return hotelService.search(requestParams);
    }

    /*Request URL: http://localhost:8089/hotel/filters
    Request Method: POST
    {"key":"","page":1,"size":5,"sortBy":"default","city":"上海"}*/
    @PostMapping("/filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams requestParams){
        log.info("[getFilters接收到数据为：RequestParams{}]",requestParams.toString());
        return hotelService.getFilters(requestParams);
    }
}
